  package org.hubwork.base.common;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.datasource.lookup.DataSourceLookup;
import org.springside.modules.test.spring.SpringContextHolder;

public class ConnectionManager {

	private static DataSourceLookup lookup = HubApplicationContext.get(DataSourceLookup.class);
	
	public static Connection getConnection (){
		
		String dsName = ContextSupport.getCurrentDataSource();
		DataSource ds = lookup.getDataSource(dsName);
		return DataSourceUtils.getConnection(ds);
	}
	
	public static void close (Statement stmt, ResultSet rs)
	  {
	    try
	    {
	      if (rs != null)
	      {
	        rs.close ();
	      }
	    }
	    catch (SQLException ex)
	    {
	      //LogUtil.error (ConnectionManager.class, "close", ex);
	    }
	    finally
	    {
	      try
	      {
	        if (stmt != null)
	        {
	          stmt.close ();
	        }
	      }
	      catch (SQLException ex)
	      {
	        //LogUtil.error (ConnectionManager.class, "close", ex);
	      }
	    }
	  }
}